
package com.zoo.mongodb

import com.mongodb.DB
import com.mongodb.DBCollection
import com.mongodb.DBCursor
import com.mongodb.BasicDBObject
import com.mongodb.MongoClient
import com.mongodb.MongoException
import com.mongodb.ServerAddress

class TestMongoDB {

    def doIt() {

        def addrs = [new ServerAddress("192.168.1.200" , 30001), new ServerAddress("192.168.1.201" , 30002),new ServerAddress("192.168.1.202" , 30003)]

	def mongo = new MongoClient(addrs)
	def db = mongo.getDB("testdb")
        def table = db.getCollection("user")

        table.drop()

	table.insert([name: "Vasill", age: 52, created: new Date()] as BasicDBObject)

	def cursor = table.find([name: "Vasill"] as BasicDBObject)
	while(cursor.hasNext()) {
            println cursor.next()
	}

	table.update([name: "Vasill"] as BasicDBObject, [$set: [name: "Vasill-updated"]] as BasicDBObject)

	def cursor2 = table.find([name: "Vasill-updated"] as BasicDBObject)
	while(cursor2.hasNext()) {
            println cursor2.next()
	}
    }

}

def test = new TestMongoDB()

println "Start"
test.doIt()
println "Done"
